<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
    String currentPage = request.getRequestURI();
    String activeClass = "active";
    // 获取用户信息
    lzy.entity.User user = (lzy.entity.User) session.getAttribute("user");
%>

<nav id="sidebarMenu" class="col-md-3 col-lg-2 d-md-block bg-light sidebar collapse">
    <div class="position-sticky pt-3">
        <!-- 个人信息展示区域 -->
        <div class="user-info text-center mb-4">
            <div class="user-avatar mx-auto mb-2">
                <i class="fa-solid fa-user-circle" style="font-size:2.5rem;color:#adb5bd;"></i>
            </div>
            <div class="user-name fw-bold" style="font-size:1.1rem;">
                <c:out value="${user.realName != null ? user.realName : user.username}"/>
            </div>
            <div class="user-role text-muted" style="font-size:0.95rem;">
                角色：
                <c:choose>
                    <c:when test="${user.role == 'ADMIN'}">管理员</c:when>
                    <c:when test="${user.role == 'PRODUCING'}">生产人员</c:when>
                    <c:when test="${user.role == 'PROCESSING'}">加工人员</c:when>
                    <c:otherwise>未知</c:otherwise>
                </c:choose>
            </div>
        </div>
        <ul class="nav flex-column">
            <li class="nav-item">
                <a class="nav-link <%= currentPage.contains("/user/profile") ? activeClass : "" %>" href="${pageContext.request.contextPath}/user/profile">
                    <i class="fa-solid fa-user"></i> 个人中心
                </a>
            </li>
            <c:choose>
                <c:when test="${sessionScope.user.role == 'ADMIN'}">
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/admin/system_overview") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/admin/system_overview">
                            <i class="fa-solid fa-gauge"></i> 系统概览
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/admin/user_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/admin/user_management">
                            <i class="fa-solid fa-users"></i> 用户管理
                        </a>
                    </li>
<%--                    <li class="nav-item">--%>
<%--                        <a class="nav-link <%= currentPage.contains("/admin/production_management") ? activeClass : "" %>"--%>
<%--                           href="${pageContext.request.contextPath}/admin/production_management">--%>
<%--                            <i class="bi bi-tree"></i> 生产管理--%>
<%--                        </a>--%>
<%--                    </li>--%>
<%--                    <li class="nav-item">--%>
<%--                        <a class="nav-link <%= currentPage.contains("/admin/processing_management") ? activeClass : "" %>"--%>
<%--                           href="${pageContext.request.contextPath}/admin/processing_management">--%>
<%--                            <i class="bi bi-gear"></i> 加工管理--%>
<%--                        </a>--%>
<%--                    </li>--%>
                </c:when>
                <c:when test="${sessionScope.user.role == 'USERB'}">
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/production/farming_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/production/farming_management">
                            <i class="fa-solid fa-gauge"></i> 农事操作管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/production/environment_monitor") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/production/environment_monitor">
                            <i class="fa-solid fa-cloud-sun"></i> 生产环境监控
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/production/crop_status") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/production/crop_status">
                            <i class="fa-solid fa-chart-line"></i> 作物状态监控
                        </a>
                    </li>
                </c:when>
                <c:when test="${sessionScope.user.role == 'PRODUCING'}">
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/production/farming_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/production/farming_management">
                            <i class="fa-solid fa-gauge"></i> 农事操作管理
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/production/environment_monitor") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/production/environment_monitor">
                            <i class="fa-solid fa-cloud-sun"></i> 生产环境监控
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/production/crop_status") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/production/crop_status">
                            <i class="fa-solid fa-chart-line"></i> 作物状态监控
                        </a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/production/greenhouse_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/production/greenhouse_management">
                            <i class="fa-solid fa-seedling"></i> 种植大棚管理
                        </a>
                    </li>
                </c:when>
                <c:when test="${sessionScope.user.role == 'PROCESSING'}">
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/processing/quality_control") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/processing/quality_control">
                            <i class="fa-solid fa-check-circle"></i> 质量控制
                        </a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/processing/equipment_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/processing/equipment_management">
                            <i class="fa-solid fa-check-circle"></i> 设备管理
                        </a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/processing/batch_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/processing/batch_management">
                            <i class="fa-solid fa-box"></i> 批次管理
                        </a>
                    </li>
<%--********************************************后添加功能****************************************--%>
                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/processing/packaging_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/processing/packaging_management">
                            <i class="fa-solid fa-box"></i> 包装管理
                        </a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/processing/warehousing_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/processing/warehousing_management">
                            <i class="fa-solid fa-box"></i> 仓储管理
                        </a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/processing/logistics_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/processing/logistics_management">
                            <i class="fa-solid fa-box"></i> 物流管理
                        </a>
                    </li>

                    <li class="nav-item">
                        <a class="nav-link <%= currentPage.contains("/processing/sales_management") ? activeClass : "" %>"
                           href="${pageContext.request.contextPath}/processing/sales_management">
                            <i class="fa-solid fa-box"></i> 销售管理
                        </a>
                    </li>
                </c:when>
            </c:choose>
        </ul>
    </div>
</nav>

<style>
.nav-link {
    color: #333;
    padding: 0.5rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link:hover {
    color: #0d6efd;
    background-color: rgba(13, 110, 253, 0.1);
}

.nav-link.active {
    color: #0d6efd;
    background-color: rgba(13, 110, 253, 0.1);
    font-weight: 500;
}

.nav-link i {
    font-size: 1.1rem;
}
.user-info {
    padding: 1.2rem 0 0.5rem 0;
    border-bottom: 1px solid #e9ecef;
}
.user-avatar {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #f1f3f4;
    display: flex;
    align-items: center;
    justify-content: center;
}
.sidebar {
    border-top-right-radius: 0 !important;
    margin-top: 0 !important;
}
</style> 